package com.moinut.studentattendancemanager.view.comment;

import com.moinut.studentattendancemanager.view.BaseFrame;
import com.moinut.studentattendancemanager.view.student.StudentLoginFrame;
import com.moinut.studentattendancemanager.view.teacher.TeacherLoginFrame;
import com.moinut.studentattendancemanager.utils.WindowJumper;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

/**
 * @author MOILING
 */
public class MainLoginFrame extends BaseFrame<MainLoginFrame.MainLoginPanel> {
    private static final long serialVersionUID = 1L;

    private static final int DEFAULT_WIDTH = 300;
    private static final int DEFAULT_HEIGHT = 260;

    public MainLoginFrame() {
        super("学生考勤管理系统", DEFAULT_WIDTH, DEFAULT_HEIGHT);
    }

    @Override
    protected MainLoginPanel onSetContentPane() {
        return new MainLoginPanel();
    }

    /*package*/ class MainLoginPanel extends JPanel implements ActionListener {
        private static final long serialVersionUID = 1L;

        private JLabel mPicLabel;
        private JButton mStudentButton, mTeacherButton;
        private JPanel mInfoPanel;

        /*package*/ MainLoginPanel() {
            setLayout(new BorderLayout());

            mPicLabel = new JLabel();
            mPicLabel.setSize(DEFAULT_WIDTH, DEFAULT_WIDTH / 2);
            ImageIcon image = new ImageIcon(this.getClass().getResource("/res/images/login_head.jpg"));
            image.setImage(image.getImage().getScaledInstance(mPicLabel.getWidth(),
                    mPicLabel.getHeight(),
                    Image.SCALE_DEFAULT));
            mPicLabel.setIcon(image);

            mStudentButton = new JButton("点击跳转到学生登录界面");
            mTeacherButton = new JButton("点击跳转到教工登录界面");

            mInfoPanel = new JPanel();
            mInfoPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
            mInfoPanel.add(mPicLabel);
            mInfoPanel.add(mStudentButton);
            mInfoPanel.add(mTeacherButton);

            add(mInfoPanel, BorderLayout.CENTER);

            mStudentButton.addActionListener(this);
            mTeacherButton.addActionListener(this);
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            if (e.getSource().equals(mStudentButton)) {
                WindowJumper.jump(MainLoginFrame.this, StudentLoginFrame.class);
                return;
            }
            if (e.getSource().equals(mTeacherButton)) {
                WindowJumper.jump(MainLoginFrame.this, TeacherLoginFrame.class);
            }
        }
    }

}
